package com.coolwen.mybatis.service;

import com.coolwen.mybatis.dao.IGroupDao;
import com.coolwen.mybatis.dao.IUserDao;
import com.coolwen.mybatis.model.Group;
import com.coolwen.mybatis.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author CoolWen
 * @version 2020-04-16 10:03
 */
@Service("userService")
@Transactional(readOnly = true)
public class UserServiceImpl implements UserService {

    @Autowired
    private IUserDao userDao;

    @Autowired
    private IGroupDao groupDao;

    @Override
    public void add(User user, int gid) {
        userDao.add(user);
    }

    @Override
    public void delete(int id) {
        userDao.delete(id);
    }

    @Override
    public void update(User user) {
        userDao.update(user);
    }

    @Override
    public User load(int id) {
        return userDao.load(id);
    }

    @Override
    public void addGroupAndUser(User user, Group group) {
        groupDao.add(group);
        try {
            int i = 1 / 0;
        } catch (Exception e) {
            e.printStackTrace();
        }
        userDao.add(user);

    }

    @Override
    public void loginUser(String username, String password) {
        User u =userDao.loadUser(username);
        if(u ==null){
            System.out.println("你输入的用户名或者密码错误!");
        }
        if(u.getPassword()!=password)
        {
            System.out.println("你输入的用户名或者密码错误!");
        }
    }
}
